package com.gitee.zhanyao.common.system;

public class OSInfo {

    private static String OS = System.getProperty("os.name").toLowerCase();

    private static OSInfo osInfo = new OSInfo();

    private OSEnum osEnum;

    private OSInfo() {
    }

    public static boolean isLinux() {
        return OS.contains("linux");
    }

    public static boolean isMacOS() {
        return OS.contains("mac") && OS.contains("os") && !OS.contains("x");
    }

    public static boolean isMacOSX() {
        return OS.contains("mac") && OS.contains("os") && OS.contains("x");
    }

    public static boolean isWindows() {
        return OS.contains("windows");
    }

    public static boolean isOS2() {
        return OS.contains("os/2");
    }

    public static boolean isSolaris() {
        return OS.contains("solaris");
    }

    public static boolean isSunOS() {
        return OS.contains("sunos");
    }

    public static boolean isMPEiX() {
        return OS.contains("mpe/ix");
    }

    public static boolean isHPUX() {
        return OS.contains("hp-ux");
    }

    public static boolean isAix() {
        return OS.contains("aix");
    }

    public static boolean isOS390() {
        return OS.contains("os/390");
    }

    public static boolean isFreeBSD() {
        return OS.contains("freebsd");
    }

    public static boolean isIrix() {
        return OS.contains("irix");
    }

    public static boolean isDigitalUnix() {
        return OS.contains("digital") && OS.contains("unix");
    }

    public static boolean isNetWare() {
        return OS.contains("netware");
    }

    public static boolean isOSF1() {
        return OS.contains("osf1");
    }

    public static boolean isOpenVMS() {
        return OS.contains("openvms");
    }

    /**
     * 获取操作系统枚举
     *
     * @return 操作系统枚举
     */
    public static OSEnum getOSEnum() {
        if (isLinux()) {
            osInfo.osEnum = OSEnum.LINUX;
        } else if (isWindows()) {
            osInfo.osEnum = OSEnum.WINDOWS;
        } else if (isMacOS()) {
            osInfo.osEnum = OSEnum.MAC_OS;
        } else if (isMacOSX()) {
            osInfo.osEnum = OSEnum.MAC_OS_X;
        } else if (isAix()) {
            osInfo.osEnum = OSEnum.AIX;
        } else if (isDigitalUnix()) {
            osInfo.osEnum = OSEnum.DIGITAL_UNIX;
        } else if (isFreeBSD()) {
            osInfo.osEnum = OSEnum.FREE_BSD;
        } else if (isHPUX()) {
            osInfo.osEnum = OSEnum.HP_UX;
        } else if (isIrix()) {
            osInfo.osEnum = OSEnum.IRIX;
        } else if (isMPEiX()) {
            osInfo.osEnum = OSEnum.MPE_IX;
        } else if (isNetWare()) {
            osInfo.osEnum = OSEnum.NET_WARE_411;
        } else if (isOpenVMS()) {
            osInfo.osEnum = OSEnum.OPEN_VMS;
        } else if (isOS2()) {
            osInfo.osEnum = OSEnum.OS2;
        } else if (isOS390()) {
            osInfo.osEnum = OSEnum.OS390;
        } else if (isOSF1()) {
            osInfo.osEnum = OSEnum.OSF1;
        } else if (isSolaris()) {
            osInfo.osEnum = OSEnum.SOLARIS;
        } else if (isSunOS()) {
            osInfo.osEnum = OSEnum.SUN_OS;
        } else {
            osInfo.osEnum = OSEnum.OTHERS;
        }
        return osInfo.osEnum;
    }

    /**
     * 获取操作系统名字
     *
     * @return 操作系统名
     */
    public static String getOSName() {
        return getOSEnum().getDescription();
    }

}